package com.yjz.middleware.netty;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class StudentProtocolServerHandler extends ChannelDuplexHandler {

  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    // 接受客户端的pojo
    Student student = (Student) msg;
    log.info("接受客户端发来的实体:{}",student.toString());

//    ByteBuf student = (ByteBuf) msg;
//    log.info("接受客户端发来的实体:{}",student.toString(CharsetUtil.UTF_8));
  }
  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (cause != null) {
      log.info(cause.getMessage());
    }
    ctx.close();

  }
}
